# -*- coding: utf-8 -*-
import re

def verify_dco_signature(commit_message, author_name, author_email):
    # 定义 DCO 签名的正则表达式
    dco_pattern = re.compile(r'Signed-off-by: (.*) <(.*)>')
    
    # 查找 DCO 签名
    match = dco_pattern.search(commit_message)
    if match:
        signed_name = match.group(1).strip()
        signed_email = match.group(2).strip()
        
        # 验证签名者的信息是否与提交者一致
        if signed_name == author_name and signed_email == author_email:
            return True  # 验证通过
        else:
            return False  # 验证失败
    else:
        return False  # 找不到 DCO 签名，验证失败

# 如果直接运行此文件，则执行测试
if __name__ == "__main__":
    # 示例数据
    commit_message = """test no sign
Signed-off-by: yangyongzhen <931023898@qq.com>"""
    author_name = "labixiaoxin"
    author_email = "931023898@qq.com"

    # 验证
    is_signed = verify_dco_signature(commit_message, author_name, author_email)
    print(f"DCO签名验证结果: {is_signed}")
